package com.gict.antifraudback.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gict.antifraudback.entity.LogExcp;
import com.gict.antifraudback.mapper.LogExcpMapper;
import com.gict.antifraudback.service.ILogExcpService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class LogExcpServiceImpl extends ServiceImpl<LogExcpMapper, LogExcp> implements ILogExcpService {

    @Override
    public IPage logExcpList(Integer pageNo, Integer pageSize, String methodName, Long startTime, Long endTime) {
        IPage<LogExcp> iPage = new Page<>(pageNo, pageSize);
        // TODO 修改字段名时注意修改
        QueryWrapper<LogExcp> excLogQuery = new QueryWrapper<LogExcp>();
        excLogQuery.select("id", "exc_name", "method", "uri", "ip", "create_time");
        if (StringUtils.isNotBlank(methodName)) {
            excLogQuery.like("method", methodName);
        }
        if (null != startTime && startTime > 0) {
            excLogQuery.ge("UNIX_TIMESTAMP(create_time)*1000", startTime);
        }
        if (null != endTime && endTime > 0) {
            excLogQuery.le("UNIX_TIMESTAMP(create_time)*1000", endTime);
        }
        excLogQuery.orderByDesc("id");
        return page(iPage, excLogQuery);
    }
}
